package utility;

import java.awt.Color;

import javax.swing.ImageIcon;

import utilPackage.Explosion;

import main.GameTree;
import main.Sprite;
import quadtree.DoublePoint;

public class ContraEnemy extends Sprite {

	Color myColor;
	
	public ContraEnemy(int x, int y, int width, int height, Color color, GameTree gameTree) {
		this.gameTree = gameTree;
		this.x = x;
		this.y = y;
		this.width = width;
		this.height = height;
		myColor = color;
		ImageIcon ii = new ImageIcon(this.getClass().getResource("Eyes.jpg"));
		this.width = ii.getImage().getWidth(null);
		this.height = ii.getImage().getHeight(null); 
		setImage(ii.getImage());
	}
	
	public void die() {
		super.die();
		DoublePoint p = new DoublePoint(x, y);
		gameTree.insertSprite(p,new Explosion((int)p.x, 
				(int)p.y, 0, 2, 15));
		gameTree.insertSprite(p,new Explosion((int)p.x, 
				(int)p.y, 2, 0, 15));
		gameTree.insertSprite(p,new Explosion((int)p.x, 
				(int)p.y, 0, -2, 15));
		gameTree.insertSprite(p,new Explosion((int)p.x, 
				(int)p.y, -2, 0, 15));
		gameTree.insertSprite(p,new Explosion((int)p.x, 
				(int)p.y, 1, 1, 20));
		gameTree.insertSprite(p,new Explosion((int)p.x, 
				(int)p.y, 1, -1, 20));
		gameTree.insertSprite(p,new Explosion((int)p.x, 
				(int)p.y, -1, -1, 20));
		gameTree.insertSprite(p,new Explosion((int)p.x, 
				(int)p.y, -1, 1, 20));
		p = new DoublePoint(x + width/2, y+height/2);
		gameTree.insertSprite(p,new Explosion((int)p.x, 
				(int)p.y, 0, 2, 15));
		gameTree.insertSprite(p,new Explosion((int)p.x, 
				(int)p.y, 2, 0, 15));
		gameTree.insertSprite(p,new Explosion((int)p.x, 
				(int)p.y, 0, -2, 15));
		gameTree.insertSprite(p,new Explosion((int)p.x, 
				(int)p.y, -2, 0, 15));
		gameTree.insertSprite(p,new Explosion((int)p.x, 
				(int)p.y, 1, 1, 20));
		gameTree.insertSprite(p,new Explosion((int)p.x, 
				(int)p.y, 1, -1, 20));
		gameTree.insertSprite(p,new Explosion((int)p.x, 
				(int)p.y, -1, -1, 20));
		gameTree.insertSprite(p,new Explosion((int)p.x, 
				(int)p.y, -1, 1, 20));
		p = new DoublePoint(x + width, y+height);
		gameTree.insertSprite(p,new Explosion((int)p.x, 
				(int)p.y, 0, 2, 15));
		gameTree.insertSprite(p,new Explosion((int)p.x, 
				(int)p.y, 2, 0, 15));
		gameTree.insertSprite(p,new Explosion((int)p.x, 
				(int)p.y, 0, -2, 15));
		gameTree.insertSprite(p,new Explosion((int)p.x, 
				(int)p.y, -2, 0, 15));
		gameTree.insertSprite(p,new Explosion((int)p.x, 
				(int)p.y, 1, 1, 20));
		gameTree.insertSprite(p,new Explosion((int)p.x, 
				(int)p.y, 1, -1, 20));
		gameTree.insertSprite(p,new Explosion((int)p.x, 
				(int)p.y, -1, -1, 20));
		gameTree.insertSprite(p,new Explosion((int)p.x, 
				(int)p.y, -1, 1, 20));
		p = new DoublePoint(x + width, y);
		gameTree.insertSprite(p,new Explosion((int)p.x, 
				(int)p.y, 0, 2, 15));
		gameTree.insertSprite(p,new Explosion((int)p.x, 
				(int)p.y, 2, 0, 15));
		gameTree.insertSprite(p,new Explosion((int)p.x, 
				(int)p.y, 0, -2, 15));
		gameTree.insertSprite(p,new Explosion((int)p.x, 
				(int)p.y, -2, 0, 15));
		gameTree.insertSprite(p,new Explosion((int)p.x, 
				(int)p.y, 1, 1, 20));
		gameTree.insertSprite(p,new Explosion((int)p.x, 
				(int)p.y, 1, -1, 20));
		gameTree.insertSprite(p,new Explosion((int)p.x, 
				(int)p.y, -1, -1, 20));
		gameTree.insertSprite(p,new Explosion((int)p.x, 
				(int)p.y, -1, 1, 20));
		p = new DoublePoint(x, y+height);
		gameTree.insertSprite(p,new Explosion((int)p.x, 
				(int)p.y, 0, 2, 15));
		gameTree.insertSprite(p,new Explosion((int)p.x, 
				(int)p.y, 2, 0, 15));
		gameTree.insertSprite(p,new Explosion((int)p.x, 
				(int)p.y, 0, -2, 15));
		gameTree.insertSprite(p,new Explosion((int)p.x, 
				(int)p.y, -2, 0, 15));
		gameTree.insertSprite(p,new Explosion((int)p.x, 
				(int)p.y, 1, 1, 20));
		gameTree.insertSprite(p,new Explosion((int)p.x, 
				(int)p.y, 1, -1, 20));
		gameTree.insertSprite(p,new Explosion((int)p.x, 
				(int)p.y, -1, -1, 20));
		gameTree.insertSprite(p,new Explosion((int)p.x, 
				(int)p.y, -1, 1, 20));
	}
	
	@Override
	public void draw() {
		//g.setColor(myColor);
		//g.fillOval(x, y, width, height);
		g.drawImage(getImage(), x, y, imageObserver);
	}

	@Override
	public void think() {
		// TODO Auto-generated method stub
	}

	@Override
	public boolean doesCollide(Sprite s) {
		int sLeftEdge = s.getX();
		int sRightEdge = s.getX()+ s.getWidth();
		int sTopEdge = s.getY();
		int sBottomEdge = s.getY() + s.getHeight();

		int leftEdge = this.x;
		int rightEdge = this.x + this.width;
		int topEdge = this.y;
		int bottomEdge = this.y + this.height;

		if( sLeftEdge <= rightEdge && 
				sRightEdge >=  leftEdge &&
				sTopEdge <= bottomEdge &&
				sBottomEdge >= topEdge ) {
			if(s instanceof ContraBullit) {
				die();
				s.die();
			}
			return true;
		}	
		return false;
	}

}
